﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Daco.Web.Store;

namespace Daco.Web.Pages
{
    public partial class Default : Daco.Web.UI.SitePage
    {
        protected int ItemsPerRow { get; set; }

        public Default()
        {
            this.ItemsPerRow = 3;
            this.Load += new EventHandler(Default_Load);
        }

        void Default_Load(object sender, EventArgs e)
        {
            rpProduct.DataSource = CProduct.GetNewestProducts();
            rpProduct.DataBind();
        }

        protected string GetPhotoUrl(object item)
        {
            Daco.Web.Store.CProduct p = (Daco.Web.Store.CProduct)item;
            return Page.ResolveUrl(string.Format("~/Handlers/PHOTOHandler.ashx?pid={0}", p.GetDefaulPhoto().PhotoID));
        }

        protected string GetPriceDetail(object item)
        {
            CProduct current = (CProduct)item;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (!current.EnablePriceConfidential && current.UnitPrice > 0)
            {
                sb.Append(@"<b>Giá: </b><label style=""color: Red;"">");
                sb.Append(current.UnitPrice.ToString(Config.CSiteConfig.Current.DoubleFormatString));
                sb.Append(current.Currency);
                sb.Append("</label>");
            }

            return sb.ToString();
        }
    }
}